package com.chuyu.cy.controller;

import com.chuyu.cy.contants.Result;
import com.chuyu.cy.entity.dto.TagDTO;
import com.chuyu.cy.entity.vo.TagVO;
import com.chuyu.cy.service.TagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 周小白
 * @date: 2024-03-15 17:13
 **/
@RestController
@RequestMapping("/tag")
@Tag(name = "标签管理")
public class TagController {

    @Resource
    private TagService tagService;



    /**
     * 获取标签列表
     * @return 标签列表
     */
    @GetMapping("/list")
    @Operation(summary = "获取标签列表")
    public Result<List<TagVO>> getTagList() {
        Result<List<TagVO>> result = new Result<>();

        List<TagVO> tagList = tagService.getTagList();

        return result.success(tagList);
    }





    /**
     * 插入标签
     * @param tagDTO 标签
     * @return result
     */
    @PostMapping("/add")
    @Operation(summary = "插入标签")
    public Result insertTag(@RequestBody TagDTO tagDTO) {
        Result result = new Result();

        if (tagDTO == null) {
            return result.failure("参数不能为空");
        }

        boolean inserted = tagService.insertTag(tagDTO);
        if (!inserted) {
            return result.failure("插入失败");
        }

        return result.success();
    }
}
